#pragma once
#include "DX9Engine.h"
#include "Input.h"

/**
 * NOTE: All texture and sprite sheet frame dimensions 
 * MUST be a power of two!
 * 1 2 4 8 16 32 64 128 256 512 1024 ...
 */
class Texture
{
protected:
	/** handle to dx9engine */
	DX9Engine* pEngine;
	/** handle to input */
	Input* pInput;
	/** texture ID */
	int		m_id;
	/** texture data */
	V2DF	m_pos;
	float	m_rot;
	float	m_scale;
	/** Opacity measured in percent from 0.0f to 1.0f */
	float	m_opacity;
	RECT	m_bounds;
	int		m_width;
	int		m_height;
	/** if an object is clickable it is also hoverable */
	bool	m_bClickable;	
	/** draw object at center if true */
	bool	m_bCentered;	

public:
	Texture(void);
	~Texture(void);

	void release();

	/** create a simple texture to render */
	void initialize(LPCWSTR fileName);
	/** initialize texture with data */
	void initialize(LPCWSTR fileName, V2DF pos, float rot, float scale, bool centered);
	/** draw sprite */
	void draw();
	/** draw sprite with custom data */
	void draw(V2DF pos, float rot, float scale, bool centered);
	/** draw sprite sheet with data */
	void draw(RECT sheet, V2DF pos, float rot, float scale, bool centered);
	/**
	 * update sprite position
	 * @param V2DF position
	 */
	void updatePosition(V2DF a_pos);
	/**
	 * update sprite rotation
	 * @param float rotation
	 */
	void updateRotation(float a_rot);
	/**
	 * update sprite scale
	 * @param float scale
	 */
	void updateScale(float a_scale);
	void updateRect();

	/** @return Get RECT */
	RECT getRect() {return m_bounds;}
	/** @return Get texture position */
	V2DF getPos() {return m_pos;}
	/** @return Get texture width */
	int getWidth() {return pEngine->getWidth(m_id);}
	/** @return Get texcture height */
	int getHeight() {return pEngine->getHeight(m_id);}

	/** 
	 * Set border rect for sprite sheet
	 * @param r rect to draw from sprite sheet
	 */
	inline void setRect(RECT r) {m_bounds = r;}
	/** Set object to hoverable */
	inline void setClickable() {m_bClickable = true;}
	/** Set object position */
	inline void setPosition(V2DF pos) {m_pos = pos;}
	/** Set object scale */
	inline void setScale(float scale) {m_scale = scale;}
	bool hovered();
};